<?php

namespace app\admin\model;

use think\Model;

class Order extends Model
{
    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'order_status_text',
        'pay_status_text',
        'type_text',
        'pay_time_text',
        'deleted_text',
        'shipping_status_text',
        'order_prom_type_text',
        'user_id_text',
        'goods_id_text'
    ];


    public function getUserList(){
        $model = model('user');
        $data = $model->getUserList();
        return $data;
    }


    public function getUserIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['user_id'];
        $list = $this->getUserList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getGoodsList(){
        $model = model('goods');
        $data = $model->getList();
        return $data;
    }


    public function getGoodsIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['goods_id'];
        $list = $this->getGoodsList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    

    
    public function getOrderStatusList()
    {
        return ['0' => __('Order_status 0'),'1' => __('Order_status 1'),'2' => __('Order_status 2'),'3' => __('Order_status 3'),'4' => __('Order_status 4'),'5' => __('Order_status 5')];
    }     

    public function getPayStatusList()
    {
        return ['0' => __('Pay_status 0'),'1' => __('Pay_status 1'),'2' => __('Pay_status 2'),'3' => __('Pay_status 3'),'4' => __('Pay_status 4')];
    }     

    public function getTypeList()
    {
        return ['0' => __('Type 0'),'1' => __('Type 1'),'2' => __('Type 2')];
    }     

    public function getDeletedList()
    {
        return ['1' => __('Deleted 1'),'0' => __('Deleted 0')];
    }     

    public function getShippingStatusList()
    {
        return ['0' => __('Shipping_status 0'),'1' => __('Shipping_status 1')];
    }     

    public function getOrderPromTypeList()
    {
        return ['0' => __('Order_prom_type 0'),'1' => __('Order_prom_type 1'),'2' => __('Order_prom_type 2'),'3' => __('Order_prom_type 3'),'4' => __('Order_prom_type 4')];
    }     

    public function getGoodsNumList()
    {
        return ['4) unsigne' => __('4) unsigne')];
    }     


    public function getOrderStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['order_status'];
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['pay_status'];
        $list = $this->getPayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['pay_time'];
        if($value){
            return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
        }else{
            return '无';
        }

    }


    public function getDeletedTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['deleted'];
        $list = $this->getDeletedList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getShippingStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['shipping_status'];
        $list = $this->getShippingStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrderPromTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['order_prom_type'];
        $list = $this->getOrderPromTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGoodsNumTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['goods_num'];
        $list = $this->getGoodsNumList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPayTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    public function getshippingList(){
//        return ['0' => __('速尔快递'),'1' => __('快捷快递')];

        $json = \think\Db::name('config')->where(['name' => 'setshipping'])->value('value');
        $arr = json_decode($json,true);
        return $arr;
    }


}
